#include <iostream>

using namespace std;

typedef long long LL;
const int N = 1e5 + 10;
int a[N];
int n, q;

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	cin >> q;
	while(q--)
	{
		int x, y; cin >> x >> y;
		LL left = 1, right = n;
		while(left < right)
		{
			LL mid = (left + right) >> 1;
			if(a[mid] >= x) right = mid;
			else left = mid + 1;
		}
		if(a[left] < x) 
		{
			cout << "0" << endl;
			continue;
		}
		int leftans = left;
		left = 1; right = n;
		while(left < right)
		{
			LL mid = (left + right + 1) >> 1;
			if(a[mid] <= y) left = mid;
			else right = mid - 1;
		}
        if(a[left] > y)
        {
            cout << "0" << endl;
            continue;
        }
		 cout << left - leftans + 1 << endl;
	}
	
	return 0;
} 
